#pragma once

#include <core/core.h>

namespace Core
{
    class CORE_API CriticalSection
    {
        const char* m_sectionName;
    public:
        CriticalSection(const char* sectionName); //we use not-safe string 'cause of speed. Use only "immortal" strings
        ~CriticalSection();

        void enter();
        void leave();
        bool tryEnter();
    };

    class SectionBlock
    {
        CriticalSection* m_section;
    public:
        SectionBlock(CriticalSection& s) : m_section(&s)
        {
            m_section->enter();
        }

        ~SectionBlock()
        {
            m_section->leave();
        }
    };
}